﻿/* Ree7 Tile Toolkit for Windows Phone
 * Copyright (C) 2011-2014 Pierre BELIN <pierre@ree7.fr>, and project contributors.
 *
 * Distributed under the Microsoft Public License (Ms-PL).
 * See accompanying file License.txt */

using System.Windows;
using Ree7.TileToolkit.Helpers;
using System.Windows.Media;

namespace Ree7.TileToolkit
{
	public enum TileSize
	{
		Small,
		Medium,
		Wide
	}

	public static class CustomTileFactory
	{
		/// <summary>
		/// Builds a CustomTile with the template you specified
		/// </summary>
		/// <param name="tileName">Unique name for this tile</param>
		/// <param name="tileContentTemplate">Template used for whatever should be displayed in this tile</param>
		/// <param name="tileSize">Size of the tile</param>
		/// <returns></returns>
		public static CustomTile GetTemplatedTile(string tileName, UIElement tileContentTemplate, TileSize tileSize) 
		{
			CustomTile container = TileContainerProvider.GetTileContainer(tileSize);
			container.Content = tileContentTemplate;
			container.Name = tileName;

			return container;
		}

		/// <summary>
		/// Returns the transform needed to match the Tile's bitmap size (eg: 336x336) with its display size in the UI
		/// (eg: 210x210 for WVGA screens). 
		/// </summary>
		public static Transform GetUITransform()
		{
			TransformGroup group = new TransformGroup();
			ScaleTransform scale = new ScaleTransform()
			{
				CenterX = 0.5,
				CenterY = 0.5,
				ScaleX = 210.0 / 336,
				ScaleY = 210.0 / 336
			};
			group.Children.Add(scale);

			return group;
		}
	}
}
